# -*- coding: utf-8 -*-
from Page.policyholderPage import policyholderPage
from Page.noscanningPage import noscanningPage
import time
from selenium.webdriver.support.ui import Select
from selenium.webdriver import ActionChains
class policyholder():
    def __init__(self,driver):
        self.driver = driver
        self.policyholderPage = policyholderPage(self.driver)
        self.noscanningPage=noscanningPage(self.driver)
    # 点击投保人信息录入
    def policyholderenter(self):
        self.driver.switch_to.default_content()
        self.driver.switch_to.frame("fraMenu")
        time.sleep(2)
        self.policyholderPage.policyholdermsgenter().click()
#     查询（投保单号）
    def query(self,GrpPropNo):
        self.driver.switch_to.default_content()
        self.driver.switch_to.frame("fraInterface")
        time.sleep(1)
        self.policyholderPage.inpGrpPropNo().send_keys(GrpPropNo)
        time.sleep(1)
        self.policyholderPage.btnquery().click()
        time.sleep(1)
# 公共池申请进去个人池
    def pool(self):
        # 公共池申请进去个人池
        self.policyholderPage.radQueryScanGridSel().click()
        time.sleep(1)
        self.policyholderPage.btnapply().click()
        time.sleep(1)
        window1 = self.driver.window_handles
        self.driver.switch_to.window(window1[-1])
        self.noscanningPage.butSubmit().click()
#   个人池
        windows2 = self.driver.window_handles
        self.driver.switch_to.window(windows2[-1])
        self.driver.switch_to.default_content()
        self.driver.switch_to.frame("fraInterface")
        time.sleep(1)
        self.policyholderPage.radScanMyInfoGridSel().click()
        time.sleep(1)
        self.policyholderPage.btnEnter().click()
        time.sleep(1)
        window3 = self.driver.window_handles
        self.driver.switch_to.window(window3[-1])
        self.driver.switch_to.default_content()
        self.driver.switch_to.frame("fraInterface")
        time.sleep(1)
        # self.policyholderPage.btnAgentDetailGridaddOne().click()
        # time.sleep(1)
    #     修改基本信息
    def modifyIfm(self,ChnlType):
        # 銷售渠道
        ActionChains(self.driver).double_click(self.policyholderPage.btnChnlType()).perform()
        time.sleep(1)
        Select(self.policyholderPage.secGrpIDType()).select_by_visible_text(ChnlType)
        time.sleep(1)
    #     团险客户经理
    def AgentManager(self,CustomerChannel,CommissionRate):
        window1 = self.driver.window_handles
        self.driver.switch_to.window(window1[-1])
        self.driver.switch_to.default_content()
        self.driver.switch_to.frame("fraInterface")
        # 客户所属渠道

        ActionChains(self.driver).double_click(self.policyholderPage.btnAgentDetailGrid1()).perform()
        time.sleep(1)
        Select(self.policyholderPage.secAgentDetailGrid1()).select_by_visible_text(CustomerChannel)
        time.sleep(1)
        #  客户经理代码/姓名
        ActionChains(self.driver).double_click(self.policyholderPage.btnAgentDetailGrid2()).perform()
        time.sleep(1)
        window2 = self.driver.window_handles
        self.driver.switch_to.window(window2[-1])
        self.driver.switch_to.default_content()
        self.driver.switch_to.frame("fraInterface")
        time.sleep(1)
        self.policyholderPage.btnAgentManagerQuery().click()
        time.sleep(1)
        self.policyholderPage.radManagerGridSel().click()
        time.sleep(1)
        self.policyholderPage.btnAgentManagerGet().click()
        time.sleep(2)
        window3 = self.driver.window_handles
        self.driver.switch_to.window(window3[-1])
        self.driver.switch_to.default_content()
        self.driver.switch_to.frame("fraInterface")
        time.sleep(1)
        self.policyholderPage.btnAgentDetailGrid5().send_keys(CommissionRate)
        time.sleep(1)
    #     投保人资料
    def Applicant(self,GrpName,GrpIDType,GrpID,SumNumPeople,MainBusiness,GrpNature,BusiCategory,Phone1,ProvinceName,CityName,CountyName
                   ,DetailAddress,ZipCode):
        # 投保人名称
        self.policyholderPage.inpGrpName().send_keys(GrpName)
        time.sleep(1)
        # 单位证件类型
        ActionChains(self.driver).double_click(self.policyholderPage.btnGrpIDType()).perform()
        time.sleep(1)
        Select(self.policyholderPage.secGrpIDType()).select_by_visible_text(GrpIDType)
        time.sleep(1)
        # 单位证件号码
        self.policyholderPage.inpGrpID().send_keys(GrpID)
        time.sleep(1)
        # 员工总数
        self.policyholderPage.inpSumNumPeople().send_keys(SumNumPeople)
        time.sleep(1)
        # 经营范围
        self.policyholderPage.inpMainBusiness().send_keys(MainBusiness)
        time.sleep(1)
        # 单位性质
        ActionChains(self.driver).double_click(self.policyholderPage.btnGrpNature()).perform()
        time.sleep(1)
        Select(self.policyholderPage.secGrpNature()).select_by_visible_text(GrpNature)
        time.sleep(1)
        # 行业分类
        ActionChains(self.driver).double_click(self.policyholderPage.btnBusiCategory()).perform()
        time.sleep(1)
        Select(self.policyholderPage.secBusiCategory()).select_by_visible_text(BusiCategory)
        time.sleep(1)
        # 单位联系电话
        self.policyholderPage.inpPhone1().send_keys(Phone1)
        time.sleep(1)
#       单位地址
        #  省
        ActionChains(self.driver).double_click(self.policyholderPage.btnProvinceName()).perform()
        time.sleep(1)
        Select(self.policyholderPage.secAddress()).select_by_visible_text(ProvinceName)
        time.sleep(1)
        # 市
        ActionChains(self.driver).double_click(self.policyholderPage.btnCityName()).perform()
        time.sleep(1)
        Select(self.policyholderPage.secAddress()).select_by_visible_text(CityName)
        time.sleep(1)
        # 区/县
        ActionChains(self.driver).double_click(self.policyholderPage.btnCountyName()).perform()
        time.sleep(1)
        Select(self.policyholderPage.secAddress()).select_by_visible_text(CountyName)
        time.sleep(1)
        # 详细地址
        self.policyholderPage.inpDetailAddress().send_keys(DetailAddress)
        time.sleep(1)
        # 邮政编码
        self.policyholderPage.inpZipCode().send_keys(ZipCode)
        time.sleep(1)
    #     联系人信息
    def LinkManifm(self,LinkMan,Phone2,EMail,MobilePhone,Department):
        # 联系人姓名
        self.policyholderPage.inpLinkMan().send_keys(LinkMan)
        time.sleep(1)
        # 联系人电话
        self.policyholderPage.inpPhone2().send_keys(Phone2)
        time.sleep(1)
        # 联系人E-MAIL
        self.policyholderPage.inpEMail().send_keys(EMail)
        time.sleep(1)
        # 联系人手机号
        self.policyholderPage.inpMobilePhone().send_keys(MobilePhone)
        time.sleep(1)
        # 联系人部门
        self.policyholderPage.inpDepartment().send_keys(Department)
        time.sleep(1)
    #     付款银行信息
    def Bankmsg(self,PayType,BankCode,BankProvince,BankCity,BankAccNo,AccName):
        # 付款方式
        ActionChains(self.driver).double_click(self.policyholderPage.btnPayType()).perform()
        time.sleep(1)
        Select(self.policyholderPage.secBankmsg()).select_by_visible_text(PayType)
        time.sleep(1)
        # 银行代码
        ActionChains(self.driver).double_click(self.policyholderPage.btnBankCode()).perform()
        time.sleep(1)
        Select(self.policyholderPage.secBankmsg()).select_by_visible_text(BankCode)
        time.sleep(1)
        # 银行省代码
        ActionChains(self.driver).double_click(self.policyholderPage.btnBankProvince()).perform()
        time.sleep(1)
        Select(self.policyholderPage.secBankmsg()).select_by_visible_text(BankProvince)
        time.sleep(1)
        # 银行市代码
        ActionChains(self.driver).double_click(self.policyholderPage.btnBankCity()).perform()
        time.sleep(1)
        Select(self.policyholderPage.secBankmsg()).select_by_visible_text(BankCity)
        time.sleep(1)
        # 银行账户
        self.policyholderPage.inpBankAccNo().send_keys(BankAccNo)
        time.sleep(1)
        # 开户名
        self.policyholderPage.inpAccName().send_keys(AccName)
        time.sleep(1)
    #     开票信息
    def Invoice(self,InvoiceType,TaxPayerType,TaxPayerNo,GSBankCode,GSAddress
                ,GSTel,TaxPayerNumberNo,GSAccNo):
        # 开票类型
        ActionChains(self.driver).double_click(self.policyholderPage.btnInvoiceType()).perform()
        time.sleep(1)
        Select(self.policyholderPage.secInvoice()).select_by_visible_text(InvoiceType)
        time.sleep(1)
        # 纳税人类别
        ActionChains(self.driver).double_click(self.policyholderPage.btnTaxPayerType()).perform()
        time.sleep(1)
        Select(self.policyholderPage.secInvoice()).select_by_visible_text(TaxPayerType)
        time.sleep(1)
        # 纳税人识别号类型
        ActionChains(self.driver).double_click(self.policyholderPage.btnTaxPayerNo()).perform()
        time.sleep(1)
        Select(self.policyholderPage.secInvoice()).select_by_visible_text(TaxPayerNo)
        time.sleep(1)
        # 纳税人识别号
        self.policyholderPage.inpTaxPayerNumberNo().send_keys(TaxPayerNumberNo)
        time.sleep(1)
        # 国税等级地址
        self.policyholderPage.inpGSAddress().send_keys(GSAddress)
        time.sleep(1)
        # 国税等级电话
        self.policyholderPage.inpGSTel().send_keys(GSTel)
        # 国税开户行
        ActionChains(self.driver).double_click(self.policyholderPage.btnGSBankCode()).perform()
        time.sleep(1)
        Select(self.policyholderPage.secInvoice()).select_by_visible_text(GSBankCode)
        time.sleep(1)
        # 国税开户行账号
        self.policyholderPage.inpGSAccNo().send_keys(GSAccNo)
        time.sleep(1)
    #     保单经办人信息
    def Policytorifm(self,PolicytorName,PolicytorIDType,PolicytorIDNo,PolicytorEmail,
                     PolicytorPhone):
        # 经办人姓名
        self.policyholderPage.inpPolicytorName().send_keys(PolicytorName)
        time.sleep(1)
        # 经办人证件类型
        ActionChains(self.driver).double_click(self.policyholderPage.btnPolicytorIDType()).perform()
        time.sleep(1)
        Select(self.policyholderPage.secPolicytorIDType()).select_by_visible_text(PolicytorIDType)
        time.sleep(1)
        # 经办人证件号码
        self.policyholderPage.inpPolicytorIDNo().send_keys(PolicytorIDNo)
        time.sleep(1)
        # 经办人邮箱
        self.policyholderPage.inpPolicytorEmail().send_keys(PolicytorEmail)
        time.sleep(1)
        # 经办人手机号
        self.policyholderPage.inpPolicytorPhone().send_keys(PolicytorPhone)
        time.sleep(1)
    #     企业经办人信息
    def ComOperatorifm(self,ComOperator,OperatorEmail,OperatorTel,
                       OperatorPhone,OperatorDepart):
        # 经办人姓名
        self.policyholderPage.inpComOperator().send_keys(ComOperator)
        time.sleep(1)
        # 经办人邮箱
        self.policyholderPage.inpOperatorEmail().send_keys(OperatorEmail)
        time.sleep(1)
        # 经办人电话
        self.policyholderPage.inpOperatorTel().send_keys(OperatorTel)
        time.sleep(1)
        # 经办人手机号
        self.policyholderPage.inpOperatorPhone().send_keys(OperatorPhone)
        time.sleep(1)
        # 经办人部门
        self.policyholderPage.inpOperatorDepart().send_keys(OperatorDepart)
        time.sleep(1)
    #     法人信息
    def Corporationifm(self,Corporation,CorIDType,CorID,CorProvinceName,
                       CorCityName,CorCountyName,CorDetailAddress):
        # 法人代表
        self.policyholderPage.inpCorporation().send_keys(Corporation)
        time.sleep(1)
        # 法人代表证件类型
        ActionChains(self.driver).double_click(self.policyholderPage.btnCorIDType()).perform()
        time.sleep(1)
        Select(self.policyholderPage.secCorporation()).select_by_visible_text(CorIDType)
        time.sleep(1)
        # 法人代表证件号码
        self.policyholderPage.inpCorID().send_keys(CorID)
        time.sleep(1)
        # 长期
        self.policyholderPage.checkboxCorISLongValid().click()
        time.sleep(1)
        # 省
        ActionChains(self.driver).double_click(self.policyholderPage.btnCorProvinceName()).perform()
        time.sleep(1)
        Select(self.policyholderPage.secCorporation()).select_by_visible_text(CorProvinceName)
        time.sleep(1)
        # 市
        ActionChains(self.driver).double_click(self.policyholderPage.btnCorCityName()).perform()
        time.sleep(1)
        Select(self.policyholderPage.secCorporation()).select_by_visible_text(CorCityName)
        time.sleep(1)
        # 区/县
        ActionChains(self.driver).double_click(self.policyholderPage.btnCorCountyName()).perform()
        time.sleep(1)
        Select(self.policyholderPage.secCorporation()).select_by_visible_text(CorCountyName)
        time.sleep(1)
        # 地址
        self.policyholderPage.inpCorDetailAddress().send_keys(CorDetailAddress)
        time.sleep(1)
    #     受益说有人信息
    def Beneficiary(self,ControlDetailGrid2,ControlDetailGrid3,ControlDetailGrid4,ControlDetailGrid6,
                    ControlDetailGrid7,ControlDetailGrid9,ControlDetailGrid11,
                    ControlDetailGrid13,ControlDetailGrid15,ControlDetailGrid17,ControlDetailGrid19):
        # 添加受益人
        self.policyholderPage.btnAddBeneficiary().click()
        time.sleep(1)
        # 姓名
        self.policyholderPage.inpControlDetailGrid2().send_keys(ControlDetailGrid2)
        time.sleep(1)
        # 股份占比
        self.policyholderPage.inpControlDetailGrid3().send_keys(ControlDetailGrid3)
        time.sleep(1)
        # 证件类型
        ActionChains(self.driver).double_click(self.policyholderPage.btnControlDetailGrid4()).perform()
        time.sleep(1)
        Select(self.policyholderPage.secBeneficiary()).select_by_visible_text(ControlDetailGrid4)
        time.sleep(1)
        # 证件号码
        self.policyholderPage.inpControlDetailGrid6().send_keys(ControlDetailGrid6)
        time.sleep(1)
        # 性别
        ActionChains(self.driver).double_click(self.policyholderPage.btnControlDetailGrid7()).perform()
        time.sleep(1)
        Select(self.policyholderPage.secBeneficiary()).select_by_visible_text(ControlDetailGrid7)
        time.sleep(1)
        # 出生日期
        self.policyholderPage.inpControlDetailGrid9().click()
        time.sleep(1)
        self.policyholderPage.inpControlDetailGrid9().send_keys(ControlDetailGrid9)
        time.sleep(1)
        # 是否长期有
        ActionChains(self.driver).double_click(self.policyholderPage.btnControlDetailGrid11()).perform()
        time.sleep(1)
        Select(self.policyholderPage.secBeneficiary()).select_by_visible_text(ControlDetailGrid11)
        time.sleep(1)
        # 省
        ActionChains(self.driver).double_click(self.policyholderPage.btnControlDetailGrid13()).perform()
        time.sleep(1)
        Select(self.policyholderPage.secBeneficiary()).select_by_visible_text(ControlDetailGrid13)
        time.sleep(1)
        # 市
        ActionChains(self.driver).double_click(self.policyholderPage.btnControlDetailGrid15()).perform()
        time.sleep(1)
        Select(self.policyholderPage.secBeneficiary()).select_by_visible_text(ControlDetailGrid15)
        time.sleep(1)
        # 区/县
        ActionChains(self.driver).double_click(self.policyholderPage.btnControlDetailGrid17()).perform()
        time.sleep(1)
        Select(self.policyholderPage.secBeneficiary()).select_by_visible_text(ControlDetailGrid17)
        time.sleep(1)
        # 详细地址
        self.policyholderPage.inpControlDetailGrid19().send_keys(ControlDetailGrid19)
        time.sleep(1)
    def overaction(self):
        # 保存

        self.policyholderPage.btnSaveCont().click()
        time.sleep(1)
        '''
        m=self.driver.switch_to_alert()
        n=len(m)
        for i in range(n):
            m[i].accept()
            m=self.driver.switch_to_alert()
        time.sleep(1)
        '''
        self.driver.switch_to_alert().accept()
        time.sleep(1)
        windows2 = self.driver.window_handles
        self.driver.switch_to.window(windows2[-1])
        self.driver.switch_to.default_content()
        self.driver.switch_to.frame("fraInterface")
        time.sleep(1)
        self.policyholderPage.btnConfirmGridSel().click()
        time.sleep(1)
        # 確認新增
        self.policyholderPage.btnconfirmSave().click()
        time.sleep(1)
        # 待
        window3 = self.driver.window_handles
        self.driver.switch_to.window(window3[-1])
        self.noscanningPage.butSubmit().click()
        time.sleep(1)
        windows4 = self.driver.window_handles
        self.driver.switch_to.window(windows4[-1])
        self.driver.switch_to.default_content()
        self.driver.switch_to.frame("fraInterface")
        time.sleep(1)
        # window5 = self.driver.window_handles
        # self.driver.switch_to.window(window5[-1])
        # self.noscanningPage.butSubmit().click()
        # time.sleep(1)
        m=self.policyholderPage.inpSumPrems().get_attribute("value")
        print(m)
        time.sleep(1)
        # 錄入完畢
        self.policyholderPage.btnGrpCont().click()
        time.sleep(1)
        window1 = self.driver.window_handles
        self.driver.switch_to.window(window1[-1])
        self.noscanningPage.butSubmit().click()
        time.sleep(1)

































